package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.PersionFlowCurrLogic;
import cn.topevery.garden.entity.dto.PersionFlowCurrDTO;
import cn.topevery.garden.entity.po.PersionFlowCurr;
import cn.topevery.garden.entity.query.PersionFlowCurrQuery;
import cn.topevery.garden.entity.vo.PersionFlowCurrVO;
import com.github.dozermapper.core.Mapper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-09-17
 */
@Api(tags = "")
@RestController
@RequestMapping("/persionFlowCurr")
public class PersionFlowCurrController extends BaseController {

    @Autowired
    private Mapper mapper;

    @Autowired
    PersionFlowCurrLogic persionFlowCurrLogic;


    /**
     * 获取分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<PersionFlowCurrVO>> listPage(@RequestBody PersionFlowCurrQuery query) {
        return JsonResult.ok(persionFlowCurrLogic.listPage(query));
    }

    @ApiOperation("新增/编辑 信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody PersionFlowCurrDTO dto) {
        persionFlowCurrLogic.saveOrUpdate(getUser().id.toString(),mapper.map(dto, PersionFlowCurr.class));
        return JsonResult.ok(true);
    }

    @ApiOperation("通过Id获取详情")
    @GetMapping("/getInfoById")
    public JsonResult<PersionFlowCurrVO> getInfoById(@RequestParam Integer id) {
        PersionFlowCurr entity = persionFlowCurrLogic.getEntity(id);
        PersionFlowCurrVO vo= mapper.map(entity, PersionFlowCurrVO.class);
        return JsonResult.ok(vo);
    }

    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody Integer[] ids) {
        persionFlowCurrLogic.deleteBatchById(getUser().id.toString(),ids);
        return JsonResult.ok(true);
    }

    @ApiOperation("导出信息")
    @GetMapping("/export")
    public void export(PersionFlowCurrQuery query, HttpServletResponse response) {
        List<PersionFlowCurrVO> list = persionFlowCurrLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "", "sheet1", PersionFlowCurrVO.class, "", response);
    }

}
